package com.haven.android.sdk;

import com.haven.android.sdk.bridge.HavenCocosBridge;
import com.haven.android.sdk.max.HavenMaxReward;

import org.json.JSONObject;

public class HavenAdSdk {

    public static void showBiddingAd(String ad_source) {
        try {
            HavenMaxReward.getInstance().showVideo(HavenCocosBridge.mainGameActivity.get(), new VideoRewardCallback() {
                @Override
                public void onAdOver() {
                    try {
                        adCallBack("ad_over_wh",ad_source);
                    } catch (Exception e) {
                    }
                }

                @Override
                public void onAdError() {
                    try {
                        HavenCocosBridge.getInstance().SdkCallback("ad_error_wh", "{}");
                    } catch (Exception e) {
                    }
                }
            });
        } catch (Exception e) {
            try {
                HavenCocosBridge.getInstance().SdkCallback("ad_error_wh", "{}");
            } catch (Exception e1) {
            }
        }
    }

    private static void adCallBack(String state,String ad_source) {
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("ad_source",ad_source);
            HavenCocosBridge.getInstance().SdkCallback(state, jsonObject.toString());
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public interface VideoRewardCallback {

        void onAdOver();

        void onAdError();
    }

}
